FROM golang:1.22.1-alpine AS builder

ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64 \
    TZ=Asia/Shanghai

WORKDIR /build

COPY . .
RUN go mod tidy

RUN cd api && go build -v -p 4 -o vxopen.out
RUN cd rpc/transform && go build -v -p 4 -o transform.out
RUN cd rpc/wechat && go build -v -p 4 -o wechat.out

FROM alpine:latest

ENV TZ=Asia/Shanghai

WORKDIR /app

COPY --from=builder /build/api/vxopen.out ./vxopen.out
COPY --from=builder /build/api/etc/vxopen-api.yaml /app/etc/vxopen-api.yaml
COPY --from=builder /build/rpc/transform/transform.out ./transform.out
COPY --from=builder /build/rpc/transform/etc/transform.yaml /app/etc/transform.yaml
COPY --from=builder /build/rpc/wechat/wechat.out ./wechat.out
COPY --from=builder /build/rpc/wechat/etc/wechat.yaml /app/etc/wechat.yaml

RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/main" > /etc/apk/repositories && \
    echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/community" >> /etc/apk/repositories
RUN apk add --no-cache busybox